package cn.fintecher.pangolin.service.manage.request;

import cn.fintecher.pangolin.common.enums.BaseSelect;
import cn.fintecher.pangolin.common.enums.UserStatus;
import cn.fintecher.pangolin.entity.mysql.QUser;
import com.querydsl.core.BooleanBuilder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.util.Objects;

@Data
public class UserRequest {
    @ApiModelProperty(value = "用户名")
    private String userName;

    @ApiModelProperty(value = "姓名")
    private String realName;

    @ApiModelProperty(value = "部门ID")
    private String departId;

    @ApiModelProperty(value = "部门code")
    private String departCode;

    public BooleanBuilder getBuilder() {
        BooleanBuilder builder = new BooleanBuilder();
        QUser qUser = QUser.user;
        builder.and(qUser.isSystem.eq(BaseSelect.NO));
        builder.and(qUser.status.ne(UserStatus.LEAVE));
        if (StringUtils.isNotBlank(this.userName)) {
            builder.and(qUser.username.eq(StringUtils.trim(this.userName)));
        }
        if (StringUtils.isNotBlank(this.realName)) {
            builder.and(qUser.realName.like("%" + StringUtils.trim(this.realName) + "%"));
        }
        if (Objects.nonNull(this.departCode)) {
            builder.and(qUser.department.departCode.like(this.departCode + "%"));
        }
        return builder;
    }
}
